<?php
namespace app\blog\admin;

use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
class Writer extends Admin
{
    public function index(){
        $order=$this->getOrder();
        $where=$this->getMap();
        $data=db('blog_writer')->where($where)->order($order)->paginate();
        return ZBuilder::make('table') 
        ->addColumns([
            ['id','ID'],
            ['realname','真实名字'],
            ['nikname','昵称'],
            ['introduce','简介'],
            ['createtime','创建时间','datetime'],
            ['updatetime','修改时间','datetime'],
            ['right_button','操作','btn']
        ])
        ->addOrder('id,realname,nikname')
        ->addFilter('id,realname,nikname,introduce')
        ->setRowList($data)
        ->setHeight('auto')
        ->addRightButtons('edit')
        ->fetch();
    }
    public function edit($id=null){
        if ($this->request->isPost()){
            $update=$this->request->post();
            $update['photo']=get_file_path($update['photo']);
            $update['updatetime']=time();
            $rs=db('blog_writer')->update($update);
            if ($rs){
                $this->success('修改成功','index');
            }else{
                $this->error('修改失败');
            }
        }
        $data=db('blog_writer')->where('id='.$id)->find();
        return ZBuilder::make('form')
        ->addFormItems([
            ['hidden','id'],
            ['text','realname','真实名字'],
            ['text','nikname','昵称'],
            ['image','photo','头像'],
            ['ckeditor','introduce','简介']
        ])
        ->fetch('',$data);
    }
}

?>